package com.ruoyi.web.controller.business;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.system.domain.TMonthlyReview;
import com.ruoyi.system.service.ITMonthlyReviewService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 月评Controller
 *
 * @author ruoyi
 * @date 2024-08-20
 */
@Controller
@RequestMapping("/business/review")
public class TMonthlyReviewController extends BaseController
{
    private String prefix = "business/review";

    @Autowired
    private ITMonthlyReviewService tMonthlyReviewService;

    @RequiresPermissions("business:review:view")
    @GetMapping()
    public String review()
    {
        return prefix + "/review";
    }

    /**
     * 查询月评列表
     */
    @RequiresPermissions("business:review:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TMonthlyReview tMonthlyReview)
    {
        startPage();
        List<TMonthlyReview> list = tMonthlyReviewService.selectTMonthlyReviewList(tMonthlyReview);
        return getDataTable(list);
    }

    /**
     * 导出月评列表
     */
    @RequiresPermissions("business:review:export")
    @Log(title = "月评", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TMonthlyReview tMonthlyReview)
    {
        List<TMonthlyReview> list = tMonthlyReviewService.selectTMonthlyReviewList(tMonthlyReview);
        ExcelUtil<TMonthlyReview> util = new ExcelUtil<TMonthlyReview>(TMonthlyReview.class);
        return util.exportExcel(list, "月评数据");
    }

    /**
     * 新增月评
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存月评
     */
    @RequiresPermissions("business:review:add")
    @Log(title = "月评", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TMonthlyReview tMonthlyReview)
    {
        return toAjax(tMonthlyReviewService.insertTMonthlyReview(tMonthlyReview));
    }

    /**
     * 修改月评
     */
    @RequiresPermissions("business:review:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        TMonthlyReview tMonthlyReview = tMonthlyReviewService.selectTMonthlyReviewById(id);
        mmap.put("tMonthlyReview", tMonthlyReview);
        return prefix + "/edit";
    }

    /**
     * 修改保存月评
     */
    @RequiresPermissions("business:review:edit")
    @Log(title = "月评", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TMonthlyReview tMonthlyReview)
    {
        return toAjax(tMonthlyReviewService.updateTMonthlyReview(tMonthlyReview));
    }

    /**
     * 删除月评
     */
    @RequiresPermissions("business:review:remove")
    @Log(title = "月评", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tMonthlyReviewService.deleteTMonthlyReviewByIds(ids));
    }
}
